HumanModel = class()
HumanModel.tex = "Project:char"

function HumanModel:init()
    self.head = Cube(0, 1, HumanModel.tex)
    self.head:addBox(-4, -8, -4, 8, 8, 8)
    self.head:rebuild()

    self.body = Cube(16, 16+1, HumanModel.tex)
    self.body:addBox(-4, 0, -2, 8, 12, 4)
    self.body:rebuild()

    self.arm0 = Cube(40, 16+1, HumanModel.tex)
    self.arm0:addBox(-3, -2, -2, 4, 12, 4)
    self.arm0:setPos(-5, 2, 0)
    self.arm0:rebuild()

    self.arm1 = Cube(40, 16+1, HumanModel.tex)
    self.arm1:addBox(-1, -2, -2, 4, 12, 4)
    self.arm1:setPos(5, 2, 0)
    self.arm1:rebuild()

    self.leg0 = Cube(0, 16+1, HumanModel.tex)
    self.leg0:addBox(-2, 0, -2, 4, 12, 4)
    self.leg0:setPos(-2, 12, 0)
    self.leg0:rebuild()

    self.leg1 = Cube(0, 16+1, HumanModel.tex)
    self.leg1:addBox(-2, 0, -2, 4, 12, 4)
    self.leg1:setPos(2, 12, 0)
    self.leg1:rebuild()
end

function HumanModel:render()
    self.head:render()
    self.body:render()
    self.arm0:render()
    self.arm1:render()
    self.leg0:render()
    self.leg1:render()
end

PlayerModel = class(HumanModel)
PlayerModel.tex = "Project:char"

function PlayerModel:init()
    HumanModel.init(self)
    self.head.yRot = 0
end

function PlayerModel:render(time,walkingScale,hx)
    self.head.xRot = hx * 0.7
    --1.6是旋转幅度,0.6662是旋转速度
    self.arm0.xRot = (math.sin(time * 0.6662 + math.pi)) * walkingScale 
    self.arm0.zRot = ((math.sin(time * 0.2812) + 1) * 0.1) * walkingScale

    self.arm1.xRot = (math.sin(time * 0.6662)) * walkingScale
    self.arm1.zRot = ((math.sin(time * 0.2312) - 1) * 0.1) * walkingScale

    self.leg0.xRot = (math.sin(time * 0.6662) * 0.8) * walkingScale
    self.leg1.xRot = (math.sin(time * 0.6662 + math.pi) * 0.8) * walkingScale

    self.head:render()
    self.body:render()
    self.arm0:render()
    self.arm1:render()
    self.leg0:render()
    self.leg1:render()
end

HandModel = class()
HandModel.tex = "Project:char"

function HandModel:init()
    self.arm1 = Cube(40, 16+1, HandModel.tex)
    self.arm1:addBox(-3, -2, -2, 4, 12, 4)
    self.arm1:setPos(-5, -3, 0)
    self.arm1:rebuild()   
end

function HandModel:render(hx)
    self.arm1.xRot = hx
    self.arm1.zRot = 0       
    self.arm1:render()   
end

